from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QApplication,QWidget,QHBoxLayout,QLabel
from PyQt5.QtWidgets import QPushButton,QCheckBox ,QButtonGroup
import sys

def on_btn_state_update(flag,text,arg):
    print(f"{flag}:{text}->{arg}")

def on_btn_submit_click():
    print("抽烟:",btn1.isChecked())
    print("喝酒:",btn2.isChecked())
    print("烫头:",btn3.isChecked())

if __name__ == '__main__':
    # 创建应用程序
    app = QApplication(sys.argv)
    # 创建窗口
    w = QWidget()
    #设置窗口标题
    w.setWindowTitle("对话框")
    
    QCheckBox("抽烟")
    QCheckBox("喝酒")
    QCheckBox("烫头")
    
    
    #  创建水平布局 HorizontalLayout    垂直布局 VerticalLayout
    root_layout = QHBoxLayout(w)
    
    btn1 = QCheckBox("抽烟")
    btn2= QCheckBox("喝酒")
    btn3 = QCheckBox("烫头")
    btn3.setChecked(True)
    btn1.stateChanged.connect(lambda flag: on_btn_state_update(0,"抽烟",flag))
    btn2.stateChanged.connect(lambda flag: on_btn_state_update(1,"喝酒",flag))
    btn3.stateChanged.connect(lambda flag: on_btn_state_update(2,"烫头",flag))
    
    
    
    root_layout.addWidget(QLabel("谦哥的三大爱好："))
    root_layout.addWidget(btn1)
    root_layout.addWidget(btn2)
    root_layout.addWidget(btn3)
    
    btn_submit = QPushButton("提交")
    btn_submit.clicked.connect(on_btn_submit_click)
    root_layout.addWidget(btn_submit)
    
    #给按钮添加/关联点击事件（函数）
    
    
    
    #显示窗口
    #提交  
    w.show()

    #等待窗口停止
    sys.exit(app.exec())